package cn.juque.abstractfactory.factory;

import cn.juque.common.exception.AppException;
import cn.juque.simplefactory.product.Car;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>BaseFactory</li>
 * </ul>
 * @date 2023-06-11 22:43:18
 **/
public abstract class BaseFactory {

    public static Car render(Class<? extends BaseFactory> clazz, String model) {
        try {
            BaseFactory factory = clazz.newInstance();
            return factory.create(model);
        } catch (Exception e) {
            throw new AppException(e);
        }
    }

    /**
     * 工厂抽象方法
     * @param model 车型
     * @return Car
     */
    abstract Car create(String model);
}
